package com.xuhnagchen.automation.service.impl;

import com.xuhnagchen.automation.entity.Result;
import com.xuhnagchen.automation.entity.UserBean;
import com.xuhnagchen.automation.mapper.UserMapper;
import com.xuhnagchen.automation.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired(required = false)
    private UserMapper userMapper;


    @Override
    public Result getUserInfo(String phone, String password, Result<UserBean> result) {
        UserBean bean = userMapper.findUserByPhone(phone);
        if (bean == null) {
            return result.message(-1, "用户不存在");
        }
        if (bean.password != password) {
            return result.message(-1, "用户密码不正确");
        }
        return result.message(1, "请求成功", bean);
    }

    @Override
    public List<UserBean> findAll() {
        return userMapper.findAll();
    }

    @Override
    public UserBean findUserById(long id) {
        return userMapper.findUserById(id);
    }

}
